#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int N=2*1e3+10;


void dfs(int u,int cur,int son[N][6],int* sonIndex,int* depth)
{
	depth[cur]=depth[u]+1;
	for(int i=0;i<sonIndex[cur];i++)
	{
		if(depth[son[cur][i]]==0)
			dfs(cur,son[cur][i],son,sonIndex,depth);
	}
	
}
void findMax(int p,int u,int cur,int* a,int son[N][6],int *sonIndex,int* depth,int* now)
{
	
	if(cur!=-1 && a[cur]!=a[p] && depth[cur]-depth[p]<=*now)
	{
		return ;
	}
	if(cur!=-1 && a[cur]!=a[p] && depth[cur]-depth[p]>*now)
	{
		*now=depth[cur]-depth[p];
	}
	for(int i=0;i<sonIndex[cur];i++)
	{
		findMax(p,cur,son[cur][i],a,son,sonIndex,depth,now);
	}
}
int main()
{
	int n;
	int a[N];
	int son[N][6];
	int sonIndex[N];
	int depth[N];
	memset(sonIndex,0,sizeof(sonIndex));
	memset(son,-1,sizeof(son));
	memset(depth,0,sizeof(depth));
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	
	for(int i=2;i<=n;i++)
	{
		int p;
		scanf("%d",&p);
		son[p][sonIndex[p]]=i;
		sonIndex[p]++;
	}
	depth[0]=0;
	dfs(0,1,son,sonIndex,depth);

	
	int ret=0;
	for(int i=1;i<=n;i++)
	{
		int t;
		findMax(i,-1,i,a,son,sonIndex,depth,&t);
		if(t>ret)
			ret=t;
	}
	printf("%d",ret);

	
	return 0;
}
